package com.blog.controller;

import com.blog.common.CommonRespDto;
import com.blog.common.RespBean;
import com.blog.seckill.orders.Orders;
import com.blog.service.OrdersBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName OrdersBaseController
 * @Destription Orders基础：增删改查
 * @Author 天堂小野花
 * @Date 2025/8/19  19:16
 * @Version 1.0
 */
@RestController
@RequestMapping("/ordersIgnore")
public class OrdersBaseController {
    @Autowired
    OrdersBaseService ordersBaseService;
    @GetMapping("/selectAllOrders")
    public CommonRespDto selectAllOrders(){
        return CommonRespDto.success(ordersBaseService.selectAllOrders());
    }
    @GetMapping("/base/selectOrdersById/{rid}")
    public CommonRespDto selectOrdersById(@PathVariable Integer rid){
        return CommonRespDto.success(ordersBaseService.selectOrdersById(rid.longValue()));
    }

    @PostMapping("/base/insertOrders")
    public RespBean insertOrders(@RequestBody Orders orders){
        if(ordersBaseService.insertOrders(orders) == 1 ){
            return RespBean.ok("添加成功");
        }
        return RespBean.error("添加失败");
    }
    @DeleteMapping("/base/deleteOrders/{rid}")
    public RespBean deleteOrdersById(@PathVariable Integer rid){
        if(ordersBaseService.deleteOrdersById(rid.longValue()) == 1){
            return RespBean.ok("删除成功");
        }
        return RespBean.error("删除失败");
    }
    @PutMapping("/base/updateOrders")
    public RespBean updateOrders(@RequestBody Orders orders){

        if(ordersBaseService.updateOrders(orders) == 1){
            return RespBean.ok("更新成功");
        }
        return RespBean.error("更新失败");
    }
}
